use serde::{Deserialize, Serialize};
use serde_json;

pub(crate) mod user;

#[derive(Debug, Serialize)]
pub(crate) struct ResultData<T> {
    code: u32,
    msg: String,
    data: T,
}

impl<T> ResultData<T> {

    /* 返回错误信息 */
    pub(crate) fn result_error(code: u32, msg: String) -> String {
        let res = ResultData {
            code,
            msg,
            data:"".to_string(),
        };
        serde_json::to_string(&res).unwrap()
    }

    /* 返回错误信息 */
    pub(crate) fn result_success(data: T) -> String
    where T: Serialize{
        let res = ResultData {
            code:0,
            msg:"成功".to_string(),
            data,
        };
        serde_json::to_string(&res).unwrap()
    }

}





